package com.crl.rcdp.sys.dao;

import com.crl.dao.BaseDao;
import com.crl.rcdp.sys.model.SysUserLogin;
import com.crl.rcdp.sys.vo.SysUserLoginSearchVO;
import org.springframework.stereotype.Repository;

/**
 * @description:
 * @author: 孔垂云
 * @version: 1.0
 * @date: 2020/6/22 11:12
 */
@Repository
public class SysUserLoginDao extends BaseDao<SysUserLogin, SysUserLoginSearchVO> {

    /**
     * 根据用户名获取用户登录信息
     */
    public SysUserLogin getByUsername(String username) {
        String sql = "SELECT user_id,username,password,status,error_times,last_login_time,change_password_time " +
                "FROM td_sys_user_login WHERE username=? AND status=0";
        return get(sql, username);
    }

    /**
     * 新增用户信息
     *
     * @param sysUserLogin
     * @return
     */
    public int add(SysUserLogin sysUserLogin) {
        String sql = "INSERT INTO td_sys_user_login(user_id,username,mobile,password,status)" +
                " VALUES(:userId,:username,:mobile,:password,0)";
        return insert(sql, sysUserLogin);
    }

    /**
     * 修改最后登录时间
     *
     * @param username
     */
    public void updateLastLoginTime(String username) {
        String sql = "update td_sys_user_login set last_login_time=now() where username=?";
        update(sql, username);
    }
}
